package com.sky.servlet;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class InitParamServlet
 */
public class InitParamServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InitParamServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		ServletConfig config=this.getServletConfig(); //get the config of this servlet.
		System.out.println(config.getServletContext()==this.getServletContext());
		ServletContext context=this.getServletContext(); //get the context param.
		Enumeration contextParams=context.getInitParameterNames();
		while(contextParams.hasMoreElements()){
			String username=(String) contextParams.nextElement();
			String password=context.getInitParameter(username);
			System.out.println(username+":"+password);
		}
		String info=this.getServletInfo();
		String name=this.getServletName();
		Enumeration params=this.getInitParameterNames();
		while(params.hasMoreElements()){
			String username=(String) params.nextElement();
			String password=this.getInitParameter(username);
			System.out.println(username+":"+password);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
